﻿using System.Collections.Generic;
using System.Runtime.CompilerServices;
using log4net;

namespace AirlineServer
{
    internal class FlightsDatabase
    {
        private readonly ILog log = LogManager.GetLogger(typeof(FlightsDatabase));

        private readonly Dictionary<string, FlightsServer> flightsServers = new Dictionary<string, FlightsServer>();

        [MethodImpl(MethodImplOptions.Synchronized)]
        public void AddServer(FlightsServer server)
        {
            flightsServers[server.Name] = server;

            if (log.IsDebugEnabled)
            {
                log.Debug("Added flights server: " + server.Name);
            }
        }

        [MethodImpl(MethodImplOptions.Synchronized)]
        public void RemoveServer(string name)
        {
            flightsServers.Remove(name);

            if (log.IsDebugEnabled)
            {
                log.Debug("Removed flights server: " + name);
            }
        }

        [MethodImpl(MethodImplOptions.Synchronized)]
        public IEnumerable<Flight> GetServerFlights(string name)
        {
            return flightsServers[name].Flights;
        }
    }
}
